package xyz.scootaloo.oj.leetcode;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

/**
 * 暴力法
 * 超出时间限制
 * @author flutterdash@qq.com
 * @since 2021/3/22 21:24
 */
public class P84a {

    @Test
    public void testFunc() {
        int[] input = {2, 1, 5, 6, 2, 3};
        System.out.println(largestRectangleArea(input));
    }

    public int largestRectangleArea(int[] heights) {
        Set<Integer> heightSet = new HashSet<>();
        int maxArea = 0, currentArea;
        for (int hei : heights) {
            if (heightSet.contains(hei))
                continue;
            heightSet.add(hei);
            currentArea = 0;
            for (int idx : heights) {
                if (idx >= hei) {
                    currentArea += hei;
                    if (currentArea > maxArea)
                        maxArea = currentArea;
                } else {
                    currentArea = 0;
                }
            }
        }
        return maxArea;
    }

}
